package com.visikard.asynctask;

import java.io.ByteArrayOutputStream;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.UploadCBImageResponse;

public class UploadCBImageTask extends BaseTask {
	public static final int POS_USERID = 0;
	public static final int POS_BAOS_PHOTO = 1;

	public UploadCBImageTask(Handler handler) {
		super(handler);
	}

	public UploadCBImageTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		long userId = (Long) params[0];
		ByteArrayOutputStream baosPhoto = (ByteArrayOutputStream) params[1];

		CouponBUS busObj = new CouponBUS();

		// Upload CBImage first
		return busObj.uploadCBImage(userId, baosPhoto);
	}

	@Override
	protected boolean handleResult(Object result) {
		UploadCBImageResponse response = (UploadCBImageResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_UPLOAD_CBIMAGE_COMPLETE;
					successMsg.obj = response.getImageResult();
					mUIHandler.sendMessage(successMsg);
					return true;
			}
		}
		return false;
	}

}
